﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Core
{
    public class ProxyQuanLi
    {

        public QuanLiSinhVien QLSV = QuanLiSinhVien.Instance;       
        public QuanLyLop QLyLop =QuanLyLop.Instance;
        public QLiTaiKhoan QLTK = QLiTaiKhoan.Instance;
        public QuanLiDSHocPhan QLHocPhan = QuanLiDSHocPhan.Instance;
        public QuanLiDKHP QLDKHocPhan = QuanLiDKHP.Instance;
        public QLDSKhoa QLKhoa = QLDSKhoa.Instance; 
        //  public BaseData a = new BaseData();
        TaiKhoan User;

        #region Khởi tạo
        private static ProxyQuanLi _Instance;
        private static object locks = new object();

        public static ProxyQuanLi Instance
        {
            get
            {
                if (_Instance == null)
                {
                    lock (locks)
                    {
                        if (_Instance == null)
                            _Instance = new ProxyQuanLi();
                    }
                }
                return _Instance;
            }
        }
        public ProxyQuanLi()
        {

        }
        public ProxyQuanLi(TaiKhoan tk)
        {
            User = tk;
        }
        #endregion

        #region Quan ly sinh vien
        public void AddSinhVien(BaseData ob)
        {
            if (User.PhanQuyen == 1)
                QLSV.Add(ob);
        }

        public void DeleteSinhVien(BaseData ob)
        {
            if (User.PhanQuyen == 1)
                QLSV.Delete(ob);
        }

        public void UpdateSinhVien(BaseData ob)
        {
            if (User.PhanQuyen == 1)
                QLSV.Update(ob);
        }

        public List<BaseData> FindAllSinhVien(Predicate<BaseData> Predicate)
        {
            return QLSV.FindAll(Predicate);
        }

        public BaseData FindSinhVien(Func<BaseData, bool> predicate)
        {
            return QLSV.Find(predicate);
        }
        #endregion

        #region Quan ly lop hoc
        public void SetQLLop(QuanLyLop qllop)
        {
            QLyLop = qllop;
        }
        public void AddLopHoc(BaseData ob)
        {
            if (User.PhanQuyen == 1)
                QLyLop.Add(ob);
        }

        public void DeleteLopHoc(BaseData ob)
        {
            if (User.PhanQuyen == 1)
                QLyLop.Delete(ob);
        }

        public void UpdateLopHoc(BaseData ob)
        {
            if (User.PhanQuyen == 1)
                QLyLop.Update(ob);
        }

        public List<BaseData> FindAllLopHoc(Predicate<BaseData> Predicate)
        {
            return QLyLop.FindAll(Predicate);
        }

        public BaseData FindLopHoc(Func<BaseData, bool> predicate)
        {
            return QLyLop.Find(predicate);
        }
        #endregion

        #region Quan ly tai khoa
        public void AddTaiKhoan(BaseData ob)
        {
            if (User.PhanQuyen == 1)
                QLyLop.Add(ob);
        }

        public void DeleteTaiKhoan(BaseData ob)
        {
            if (User.PhanQuyen == 1)
                QLyLop.Delete(ob);
        }

        public void UpdateTaiKhoan(BaseData ob)
        {
            if (User.PhanQuyen == 1)
                QLyLop.Update(ob);
        }

        public List<BaseData> FindAllTaiKhoan(Predicate<BaseData> Predicate)
        {
            return QLyLop.FindAll(Predicate);
        }

        public BaseData FindTaiKhoan(Func<BaseData, bool> predicate)
        {
            return QLyLop.Find(predicate);
        }
        #endregion

        #region Quan Ly hoc Phan
        public void AddHocPhan(BaseData ob)
        {
            if (User.PhanQuyen == 1)
                QLyLop.Add(ob);
        }

        public void DeleteHocPhan(BaseData ob)
        {
            if (User.PhanQuyen == 1)
                QLyLop.Delete(ob);
        }

        public void UpdateHocPhan(BaseData ob)
        {
            if (User.PhanQuyen == 1)
                QLyLop.Update(ob);
        }

        public List<BaseData> FindAllHocPhan(Predicate<BaseData> Predicate)
        {
            return QLyLop.FindAll(Predicate);
        }

        public BaseData FindHocPhan(Func<BaseData, bool> predicate)
        {
            return QLyLop.Find(predicate);
        }
        #endregion

        public void Login(Form frmAdmin, Form frmUser, TaiKhoan tk)
        {
            User=tk;
            if (User.PhanQuyen == 1)           
                frmAdmin.ShowDialog();            
            else
                frmUser.ShowDialog();

        }

    }
}
